import pytest
from config import BASE_URL
from page.page_login import LoginPage
from script import log
from tools import DriverTools
from tools import read_json


class TestLogin(object):
    def setup_method(self):
        driver = DriverTools.get_driver()
        driver.get(BASE_URL+"/common/member/login#?type=1")
        self.log = LoginPage(driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.quit_driver()



    arg_names = "phone,pwd,expect,img"

    @pytest.mark.parametrize(arg_names, read_json("login_data.json"))
    def test_login(self, phone, pwd, expect, img):
        # 调用方法：只考虑页面怎么操作的
        self.log.login(phone, pwd)
        # 打印结果
        if phone == expect:
            result = self.log.get_success_result()
        else:
            result = self.log.get_error_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert expect in result
        self.log.get_shot(img)

    # def test01_log_success(self):
    #     self.log.login("18683060000", "abc123")
    #     self.log.get_shot("login_success.png")
    #     print(self.log.get_success_result())
    #     assert "18683060000" in self.log.get_success_result()
    #
    # def test02_log_fail(self):
    #     self.log.login("1868306000", "abc123")
    #     print(self.log.get_error_result())
    #     assert "用户不存在" or "密码错误" in self.log.get_error_result()
    #     self.log.get_shot("login_fail01.png")
    #
    # def test03_log_fail(self):
    #     self.log.login("18683060000", "123456")
    #     print(self.log.get_error_result())
    #     assert "用户不存在" or "密码错误" in self.log.get_error_result()
    #     self.log.get_shot("login_fail02.png")
